package com.bianguo.android.functiondemo.presenter;

import com.bianguo.android.functiondemo.model.BaseModel;
import com.bianguo.android.functiondemo.view.IBaseView;

import java.lang.ref.WeakReference;

public class BasePresenter<V extends IBaseView, M extends BaseModel> {

    protected M mModel;
    protected WeakReference<V> mReference;

    public BasePresenter(V mView) {
        mReference = new WeakReference<>(mView);
    }

    public void destroy() {
        if (mReference != null) {
            mReference.clear();
            mReference = null;
        }
    }

    public V getView() {
        if (mReference != null) {
            return mReference.get();
        }
        return null;
    }
}
